#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>

typedef int dataType;


typedef struct Node
{
	dataType x;
	dataType index;
	struct Node* next;
}Lnode;


void initA(Lnode* p)
{
	p->x = 7;
	p->index = 0;

	Lnode* cur = (Lnode*)malloc(sizeof(Lnode));
	cur->x = 3;
	cur->index = 1;

	p->next = cur;

	cur = (Lnode*)malloc(sizeof(Lnode));

	cur->x = 9;
	cur->index = 8;

	p->next->next = cur;

	cur = (Lnode*)malloc(sizeof(Lnode));

	cur->x = 5;
	cur->index = 17;

	p->next->next->next = cur;

	p->next->next->next->next = NULL;




}



void initB(Lnode* p)
{
	p->x = 8;
	p->index = 1;

	Lnode* cur = (Lnode*)malloc(sizeof(Lnode));
	cur->x = 22;
	cur->index = 7;

	p->next = cur;

	cur = (Lnode*)malloc(sizeof(Lnode));

	cur->x = -9;
	cur->index = 8;

	p->next->next = cur;



	p->next->next->next = NULL;



}



void setCX(Lnode* p, Lnode* p1, Lnode* p2) {

	while (p1 && p2)
	{

		Lnode* cur1 = p1;
		Lnode* cur2 = p2;
		Lnode* cur = p;
		if (cur1->index < cur2->index)
		{
			Lnode* node = (Lnode*)malloc(sizeof(Lnode));
			node->index = cur1->index;
			node->x = cur1->x;
			node->next = NULL;
			cur = node;

			cur = cur->next;
			cur1 = cur1->next;


		}
		else if (cur1->index > cur2->index)
		{
			Lnode* node = (Lnode*)malloc(sizeof(Lnode));
			node->index = cur2->index;
			node->x = cur2->x;
			node->next = NULL;
			cur = node;


			cur = cur->next;

			cur2 = cur2->next;

		}
		else
		{
			Lnode* node = (Lnode*)malloc(sizeof(Lnode));
			node->index = cur1->index;
			node->x = cur1->x + cur2->x;
			node->next = NULL;

			cur = node;


			cur = cur->next;
			cur1 = cur1->next;
			cur2 = cur2->next;

		}


		if (p1 != NULL && p2 == NULL)
		{
			while (p1)
			{
				Lnode* node = (Lnode*)malloc(sizeof(Lnode));

				node->index = cur1->index;
				node->x = cur1->x;
				node->next = NULL;
				cur = node;

				cur = cur->next;
				cur1 = cur1->next;
			}


		}
		else if (p1 == NULL && p2 != NULL)
		{

			while (p2)
			{
				Lnode* node = (Lnode*)malloc(sizeof(Lnode));

				node->index = cur1->index;
				node->x = cur2->x;
				node->next = NULL;
				cur = node;

				cur = cur->next;
				cur2 = cur2->next;
			}

		}



		/*printf("C(X)=A(X)+B(x)");
		printf("C(%d)=7+11*%d^1+22*%d^7+5*%d^17",x,x,x,x);*/


	}

	int main()
	{





		return 0;
	}